package com.ktgj.customer.service.impl;

import java.util.List;

import com.ktgj.customer.domain.CaseMalfeasance;
import com.ktgj.customer.domain.GuaranteeCase;
import com.ktgj.customer.domain.vo.GuaranteeCaseParameterVo;
import com.ktgj.customer.mapper.GuaranteeCaseMapper;
import com.ktgj.customer.service.IGuaranteeCaseService;
import com.ktgj.customer.service.IGuaranteeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.customer.mapper.CaseComplaintMapper;
import com.ktgj.customer.domain.CaseComplaint;
import com.ktgj.customer.service.ICaseComplaintService;

import javax.annotation.Resource;

/**
 * 投诉工单Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-05-27
 */
@Service
public class CaseComplaintServiceImpl implements ICaseComplaintService 
{
    @Autowired
    private CaseComplaintMapper caseComplaintMapper;
    @Resource
    private GuaranteeCaseMapper guaranteeCaseMapper;
    @Resource
    private IGuaranteeCaseService guaranteeCaseService;

    /**
     * 查询投诉工单
     * 
     * @param caseComplaintId 投诉工单ID
     * @return 投诉工单
     */
    @Override
    public CaseComplaint selectCaseComplaintById(Long caseComplaintId)
    {
        GuaranteeCase guaranteeCase = guaranteeCaseMapper.selectCaseComplaintById(caseComplaintId);
        CaseComplaint caseComplaint = caseComplaintMapper.selectCaseComplaintById(caseComplaintId);
        caseComplaint.setCaseId(guaranteeCase.getCaseId());
        try
        {
            GuaranteeCaseParameterVo guaranteeCaseParameterVo = guaranteeCaseService.backGuaranteeCaseById(guaranteeCase.getCaseId());
            caseComplaint.setGuaranteeCase(guaranteeCaseParameterVo);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return caseComplaint;
    }

    /**
     * 查询投诉工单列表
     * 
     * @param caseComplaint 投诉工单
     * @return 投诉工单
     */
    @Override
    public List<CaseComplaint> selectCaseComplaintList(CaseComplaint caseComplaint)
    {
        return caseComplaintMapper.selectCaseComplaintList(caseComplaint);
    }

    /**
     * 新增投诉工单
     * 
     * @param caseComplaint 投诉工单
     * @return 结果
     */
    @Override
    public int insertCaseComplaint(CaseComplaint caseComplaint)
    {
        return caseComplaintMapper.insertCaseComplaint(caseComplaint);
    }

    /**
     * 修改投诉工单
     * 
     * @param caseComplaint 投诉工单
     * @return 结果
     */
    @Override
    public int updateCaseComplaint(CaseComplaint caseComplaint)
    {
        if (caseComplaint.getGuaranteeCase() != null)
        {
            GuaranteeCaseParameterVo guaranteeCaseParameterVo = caseComplaint.getGuaranteeCase();
            GuaranteeCase guaranteeCase = new GuaranteeCase();
            guaranteeCase.setCaseStatus(Long.valueOf(guaranteeCaseParameterVo.getWorkOrderStatus()));
            guaranteeCaseService.updateGuaranteeCase(guaranteeCase);
        }
        if (caseComplaint.getGuaranteeCase() != null)
        {
            GuaranteeCaseParameterVo guaranteeCaseParameterVo = caseComplaint.getGuaranteeCase();
            GuaranteeCase guaranteeCase = new GuaranteeCase();
            guaranteeCase.setCaseId(guaranteeCaseParameterVo.getCaseId());
            guaranteeCase.setCaseStatus(Long.valueOf(guaranteeCaseParameterVo.getWorkOrderStatus()));
            guaranteeCaseService.updateGuaranteeCase(guaranteeCase);
        }
        return caseComplaintMapper.updateCaseComplaint(caseComplaint);
    }

    /**
     * 批量删除投诉工单
     * 
     * @param caseComplaintIds 需要删除的投诉工单ID
     * @return 结果
     */
    @Override
    public int deleteCaseComplaintByIds(Long[] caseComplaintIds)
    {
        return caseComplaintMapper.deleteCaseComplaintByIds(caseComplaintIds);
    }

    /**
     * 删除投诉工单信息
     * 
     * @param caseComplaintId 投诉工单ID
     * @return 结果
     */
    @Override
    public int deleteCaseComplaintById(Long caseComplaintId)
    {
        return caseComplaintMapper.deleteCaseComplaintById(caseComplaintId);
    }
}
